package com.lixw.langchain.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.NoApiKeyException;
import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.output.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: WanxImageModelController
 * @Description:
 * @Author: xuweiLi
 * @Create: 2025/8/24 10:37
 **/
@Slf4j
@RestController
public class WanxImageModelController {
    @Autowired
    private WanxImageModel wanxImageModel;

    @GetMapping(value = "/image/create2")
    public String createImage2() {
        Response<Image> imageResponse = wanxImageModel.generate("给我生成一个王者荣耀最厉害的辅助把");
        log.info("返回数据：{}",imageResponse.content().url().toString());
        return imageResponse.content().url().toString();
    }

    @GetMapping(value = "/images/create3")
    public String createImage3() {
        String prompt = "近景镜头，18岁的中国女孩，性感服饰，网红脸，正面看着镜头，" +
                "性感的服装，黑丝，商业摄影，室外，电影级光照，半身特写，精致的淡妆，锐利的边缘。";
        ImageSynthesisParam param = ImageSynthesisParam.builder()
                .apiKey(System.getenv("QWEN_API_KEY"))
                .model(ImageSynthesis.Models.WANX_V1)
                .prompt(prompt)
                .style("<watercolor>")
                .n(1)
                .size("1024*1024")
                .build();
        ImageSynthesis imageSynthesis = new ImageSynthesis();
        //图像合成结果
        ImageSynthesisResult result = null;
        try {
            result = imageSynthesis.call(param);
        } catch (NoApiKeyException e) {
            throw new RuntimeException(e);
        }
        System.out.println(JSONUtil.toJsonStr(result));
        return result.toString();
    }
}